package com.hrt.manage.comments.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.Replys;
import com.hrt.manage.comments.dao.ReplysDao;

@Repository
public class ReplysDaoImpl extends BaseDaoImpl<Replys> implements ReplysDao{
	/**  按是否删除查询	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Replys> findDelAll() {
		return getHibernateTemplate().find("FROM Replys WHERE isdelete=0");
	}
	
	/**分页查询的重写*/
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List<Replys> queryPageByCondition(List conditions,
			int pageIndex, int pageSize) {
		String hql = "select replys from Replys replys";
		Map delcon = new HashMap();
		delcon.put("field", "isdelete");
		delcon.put("value", 0);
		conditions.add(delcon);
		for (int i = 0; i < conditions.size(); i++) {
			Map con = (Map) conditions.get(i);
			String field = con.get("field").toString();
			String val = con.get("value").toString();
			if (i == 0) {
				hql = hql + " where replys." + field + "=" + val;
			} else {
				hql = hql + " and replys." + field + "=" + val;
			}
		}
		List<Replys> results = queryByPage(hql, pageIndex, pageSize);
		return results;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Replys> getReplysBycommId(Long commentsId) {
		return this.getHibernateTemplate().find("FROM Replys re WHERE re.isdelete=0 and re.commentsId = '"+commentsId+"'");
	}
}
